/**
 * @name         RepNET Bill Entry Controller
 * @version      1.0a
 * @author 		 Thusira Dissanayake <thusira14@gmail.com>
 * @about        Developed by MiDi
 * @license	 http://www.gnu.org/licenses/lgpl-2.1.html GNU Lesser General Public License (LGPL)
 * @lastModified 2012.09.24
 */
package com.midi.repnet.main;

/**
 * Class to handle Bill Entry data entry
 * @author Prabodha
 * 
 */
import java.sql.*;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class BillEntry {

	static String sql;

	public boolean submitData(String billNo, int agency_id, int shop_id,
			String descripton, float amount) {
		boolean val;
		DecimalFormat df = new DecimalFormat();
        df.setMinimumFractionDigits(2);
        df.setMaximumFractionDigits(2);
        df.setGroupingUsed(false);
        Calendar currentDate = Calendar.getInstance();
        SimpleDateFormat formatter= 
        new SimpleDateFormat("yyyy-MM-dd");
        String dateNow = formatter.format(currentDate.getTime());

		try {
			Statement statement = Main.dbConnection.createStatement();

			sql = "INSERT INTO transactions"
					+ "(bill_no,agency_id,shop_id,description,amount,remainder,date)"
					+ "VALUES" + "('" + billNo + "','" + agency_id + "','"
					+ shop_id + "','" + descripton + "','" + df.format(amount) + "','"
					+ df.format(amount) + "','" + dateNow + "')";
			// The same value of the amount insert to remainder
			statement.executeUpdate(sql);
			System.out.println("Record is inserted into Transaction table!");
			val = true;

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			val = false;
		}
		return val;
	}
}
